/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.coordinadores;

import DBMS.DataBaseManager;
import clases.Coordinador;
import clases.Institucion;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class Consultar extends DispatchAction {

    public ActionForward find(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.setAttribute("instituciones", Institucion.getAll()); // Necesitado para mostrar nombre de institucion
        Coordinador c = (Coordinador) form;
        System.out.println("el id de institucion recibido fue: " + c.getId());
        if(c.getId() != 0 ){
            Institucion i = new Institucion();
            i.setId(c.getId());
            c.agregarInstitucion(i);
        }
        DataBaseManager dbms = DataBaseManager.getInstance();
        ArrayList l = dbms.consultarCoordinador(c);
        if (l.isEmpty()) {
            c.setMensaje("No se encontraron coincidencias.");
            return mapping.findForward("failure");
        } else {
            request.setAttribute("coordinadores", l);
            return mapping.findForward("success");
        }
    }

    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.setAttribute("instituciones", Institucion.getAll()); // Necesitado para mostrar nombre de institucion
        return mapping.findForward("failure");
    }
}
